#ifndef ODN_INPUTDEVICE_H
#define ODN_INPUTDEVICE_H

#include "ODN_Containers.h"
#include "ODN_Maths.h"

namespace ouden {

typedef short KeyCode;
typedef short MouseButton;

//TODO: Think about mouse button being a bit field

class IInputReceiver;

//Abstract input device interface
class IInputDevice
{
	public:
		
		virtual ~IInputDevice() 	{}
		
		void addInputReceiver(IInputReceiver* pInputReceiver)
		{
			m_pInputReceivers.push_back(pInputReceiver);
		}
		
		void update();
		
		//Captures the state of input devices
		virtual void 	captureInput() = 0;
		
		//Interface methods
		virtual bool 	isKeyDown(KeyCode iKey) = 0;
		virtual Vector 	getMousePos() = 0;
		virtual Vector 	getMouseRel() = 0;
		virtual bool 	isMouseButtonDown(short iButton) = 0;
		//TODO: Add mouse displacement vector and more
		
	protected:
		
		IInputDevice() 		{}
		
		//Call this to inform all InputReceivers when a key is pushed down
		void informKeyDown(KeyCode iKey);
		
		//Call this to inform all InputReceivers when a key is released
		void informKeyUp(KeyCode iKey);
		
		//Call this to inform all InputReceivers when a key is pressed and released
		void informKeyPress(KeyCode iKey);
		
		//Call this to inform all InputReceivers when the mouse is moved
		void informMouseMove(Vector vPos, MouseButton iButtonState);
		
		//Call these to inform all InpurReceivers when a mouse button event occurs
		void informMouseButtonDown(Vector vPos, MouseButton iButton);
		void informMouseButtonUp(Vector vPos, MouseButton iButton);
		void informMouseButtonPress(Vector vPos, MouseButton iButton);
		
		//TODO: More inform functions for mouse
		
	private:
		
		//Array of registered input receivers
		Array<IInputReceiver*> m_pInputReceivers;
		
};

class IInputReceiver
{
	
public:
	
	virtual void onUnBufInput(IInputDevice* pInput) = 0;
	virtual void onKeyDown(KeyCode iKey) = 0;
	virtual void onKeyUp(KeyCode iKey) = 0;
	virtual void onKeyPress(KeyCode iKey) = 0;
	//TODO: Enable the following when buffered mouse input is being implemented
	virtual void onMouseMove(Vector vPos, MouseButton iButtonState) = 0;
	virtual void onMouseButtonDown(Vector vPos, MouseButton iButton) = 0;
	virtual void onMouseButtonUp(Vector vPos, MouseButton iButton) = 0;
	virtual void onMouseButtonPress(Vector vPos, MouseButton iButton) = 0;
	
	
};

} //namespace ouden

#endif //ODN_INPUTDEVICE_H
